//
//  LLMainTabBarVC.swift
//  IOSWeibo
//
//  Created by 廖灵全 on 16/5/10.
//  Copyright © 2016年 liao. All rights reserved.
//

import UIKit

class LLMainTabBarVC: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // 1.定义闭包
        //会modal出一个控制器    modal就是点击会从下往上弹出一个控制器
        let modalController = { ()->() in
          print("modal到了")
        }
    
           //自定义一个人tabBar
          let mainTB = LLMainTabBar()
        // 2.传递闭包
        mainTB.modalController = modalController
        
        // get,只读的属性,没有set方法, = 赋值调用的是set放法,只读属性没有了set就不能用=直接赋值
        // 使用KVC,KVC会先去找set方法如果没有set方法会找_tabBar成员变量,KVC使用运行时
        //        tabBar = mainTabBar
        //这里是把自己写的mainTB赋值给了系统的tabBar
        setValue(mainTB, forKey: "tabBar")

        
      setupChawderVC() 
    }
    //设置tabBar子控制
    func setupChawderVC(){
        //首页
        let homeVC = LLHomeVC()
//        homeVC.title="首页"
//        homeVC.tabBarItem.image = UIImage(named: "tabbar_home")
        addChildViewController(homeVC,title: "首页",image:"tabbar_discover")
        //发现
        let discoveryVC = LLDiscoveryVC()
        addChildViewController(discoveryVC,title: "发现",image:"tabbar_discover" )
        //信息
        let messagaVC = LLMessageVC()
        addChildViewController(messagaVC, title: "信息", image: "tabbar_message_center")
        //我
        let profileVC = LLProfileVC()
        addChildViewController(profileVC, title: "我", image: "tabbar_message_center")
        
    }
     // 添加子控制器,设置标题和图片名称,并且包装导航控制器
    func addChildViewController(controller: UIViewController,title:String,image:String)
    {
        //设置标题
        controller.title = title
        //设置tabBar图片
        controller.tabBarItem.image = UIImage(named: image)
        //设置文字颜色
        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Normal)
        // 包装导航控制器
        self.addChildViewController(UINavigationController(rootViewController:controller))

    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
